package bag.servlet;

import bag.c3p0Untils.PageBean;
import bag.domain.Product;
import bag.service.CartService;
import bag.service.impl.CartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/10/26.
 */
@WebServlet(name = "PageServlet",urlPatterns = "/pageServlet")
public class PageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageSize=10;
        String scurrentPage = request.getParameter("currentPage");
        int currentPage=1;
        if(scurrentPage == null){
            currentPage = 1;//从第一页开始访问
        }else{
            currentPage = Integer.parseInt(scurrentPage);
        }
        CartService service = new CartServiceImpl();
        PageBean<Product> pageBean = service.findPage(currentPage,pageSize);
        request.setAttribute("pageBean",pageBean);
        request.getRequestDispatcher("page.jsp").forward(request,response);
    }
}
